﻿<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" 
				xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
				xmlns:exslt="http://exslt.org/common" 
				xmlns:ms="urn:schemas-microsoft-com:xslt"
				xmlns:msxml="urn:schemas-microsoft-com:xslt"
			    xmlns:mv="urn:my-scripts">
  <xsl:output method="html" version="4.0" encoding="iso-8859-1" indent="yes" />
  <xsl:param name="filter" />
  <xsl:variable name="curnode" select="Results/ExportObject/ResourceManagementObject[ObjectIdentifier = $filter]/ResourceManagementAttributes" />
  <xsl:variable name="maAttributes" select="mv:parse($curnode/ResourceManagementAttribute[AttributeName='SyncConfig-attribute-inclusion']/Value)" />

	<xsl:template match="/">
    <table id="tdata">
		<xsl:call-template name="tablestyle" />
      <tr>
        <td colspan="2">
          <xsl:call-template name="reportheadstyle" />
          <xsl:text>Management Agent</xsl:text>
        </td>
      </tr>
		<tr>
			<td>
				<table>
					<xsl:call-template name="innertable" />
					<xsl:call-template name="DataItem">
						<xsl:with-param name="property">Name</xsl:with-param>
						<xsl:with-param name="value" select="$curnode//ResourceManagementAttribute[AttributeName='DisplayName']/Value" />
					</xsl:call-template>

					<xsl:call-template name="DataItem">
						<xsl:with-param name="property">Typ</xsl:with-param>
						<xsl:with-param name="value" select="$curnode//ResourceManagementAttribute[AttributeName='SyncConfig-category']/Value" />
					</xsl:call-template>

					<xsl:variable name="dn1" select="substring-after($curnode//ResourceManagementAttribute[AttributeName='SyncConfig-dn-construction']/Value, '&lt;attribute&gt;')" />
					<xsl:variable name="dn2" select="substring-before($dn1, '&lt;')" />


					<xsl:call-template name="DataItem">
						<xsl:with-param name="property">DN</xsl:with-param>
						<xsl:with-param name="value" select="$dn2" />
					</xsl:call-template>

					<xsl:variable name="pwdsync">
						<xsl:choose>
							<xsl:when test="$curnode//ResourceManagementAttribute[AttributeName='SyncConfig-password-sync-allowed']/Value='1'">Yes</xsl:when>
							<xsl:when test="$curnode//ResourceManagementAttribute[AttributeName='SyncConfig-password-sync-allowed']/Value='0'">No</xsl:when>
							<xsl:otherwise>
								<xsl:text>Unknown</xsl:text>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:variable>

					<xsl:call-template name="DataItem">
						<xsl:with-param name="property">Password Synchronization</xsl:with-param>
						<xsl:with-param name="value" select="$pwdsync" />
					</xsl:call-template>


					<xsl:variable name="cleanup1" select="substring-after($curnode/ResourceManagementAttribute[AttributeName='SyncConfig-provisioning-cleanup']/Value, '&lt;action&gt;')" />
					<xsl:variable name="cleanup2" select="substring-before($cleanup1, '&lt;')" />


					<xsl:variable name="deprovisioning">
						<xsl:value-of select="$curnode/ResourceManagementAttribute[AttributeName='SyncConfig-provisioning-cleanup-type']/Value"/>
						<xsl:text>: </xsl:text>
						<xsl:value-of select="$cleanup2"/>
					</xsl:variable>

					<xsl:call-template name="DataItem">
						<xsl:with-param name="property">Deprovisioning</xsl:with-param>
						<xsl:with-param name="value" select="$deprovisioning" />
					</xsl:call-template>

					<xsl:variable name="sync-configid" select="$curnode/ResourceManagementAttribute[AttributeName='SyncConfig-id']/Value"  ></xsl:variable>
					<xsl:call-template name="DataList">
						<xsl:with-param name="displayname">1</xsl:with-param>
						<xsl:with-param name="property">Synchronization Rules</xsl:with-param>
						<xsl:with-param name="list" select="//ResourceManagementObject[ObjectType='SynchronizationRule']/ResourceManagementAttributes[ResourceManagementAttribute/AttributeName='ConnectedSystem' and ResourceManagementAttribute/Value=$sync-configid]" />
					</xsl:call-template>
					
					<xsl:call-template name="DataList">
						<xsl:with-param name="displayname">0</xsl:with-param> 
						<xsl:with-param name="property">Selected Attributes</xsl:with-param>
						<xsl:with-param name="list" select="$maAttributes/attribute" />
					</xsl:call-template>
				</table>
			</td>
		</tr>	
		
		
   
		<xsl:if test="count($curnode[AttributeName='SyncConfig-export-attribute-flow']/Value/Values) > 0">
			<xsl:call-template name="eafflows">
				<xsl:with-param name="eafnodelist" select="$curnode[AttributeName='SyncConfig-export-attribute-flow']/Value/Values" />
			</xsl:call-template>
		</xsl:if>
    </table>
	

  </xsl:template>

	<!--===================================================================================================================================-->
	<!-- EAF Flows                                                                                                                         -->
	<!--===================================================================================================================================-->
	<xsl:template name="eafflows">
	<xsl:param name="eafnodelist" />
		<tr>
			<td colspan="2">
				<xsl:call-template name="reportheadstyle" />
				<xsl:text>Export Attribute Flows</xsl:text>
			</td>
		</tr>
		<xsl:for-each select="$eafnodelist/export-flow-set">
			<tr>
				<td colspan="2">
					<xsl:call-template name="sectionstyle" />
					<xsl:text>MV Object Type </xsl:text>
					<xsl:value-of select="@mv-object-type"/>
					<xsl:text> - CD Object Type </xsl:text>
					<xsl:value-of select="@cd-object-type"/>
				</td>
			</tr>
			<tr>
				<td>
					<table>
						<xsl:call-template name="innertable" />
						<tr>
							<th><xsl:call-template name="headstyle" />SR Flow</th>
							<th><xsl:call-template name="headstyle" />Allow Nulls</th>
							<th><xsl:call-template name="headstyle" />Initial Flow</th>
							<th><xsl:call-template name="headstyle" />Destination</th>
							<th><xsl:call-template name="headstyle" />Source</th>
						</tr>
						<xsl:for-each select="export-flow">
							<tr>
								<td></td>
								<td></td>
								<td>
									<xsl:value-of select="@cd-attribute"/>
								</td>

								<td>
									<xsl:value-of select="@cd-attribute"/>
								</td>
								<td></td>
							</tr>
						</xsl:for-each>
					</table>
				</td>
			</tr>
		</xsl:for-each>
	</xsl:template>
	<!--===================================================================================================================================-->
	<!-- Template to display a data iten                                                                                                   -->
	<!--===================================================================================================================================-->
 	<xsl:template name="DataItem">
    <xsl:param name="property" />
    <xsl:param name="value" />
    <tr>
      <th>
        <xsl:attribute name="style">
          text-align:left;
          background:#CCCCCC;
          padding-left:10px;
          padding-right:10px;
          padding-top:2px;
          padding-bottom:2px;
          font-weight:normal;
        </xsl:attribute>
        <xsl:value-of select="$property"/>
      </th>
      <th>
        <xsl:attribute name="style">
          text-align:left;
          font-weight:normal;
          padding-left:10px;
          padding-right:10px;
          padding-top:2px;
          padding-bottom:2px;
        </xsl:attribute>
        <xsl:value-of select="$value"/>
      </th>
    </tr>
  </xsl:template>
	<!--===================================================================================================================================-->
	<!-- Template to display a data list                                                                                                   -->
	<!--===================================================================================================================================-->
	<xsl:template name="DataList">
		<xsl:param name="property" />
		<xsl:param name="list" />
		<xsl:param name="displayname" />
		<tr>
			<td>
				<xsl:attribute name="style">
					vertical-align:top;
					text-align:left;
					background:#CCCCCC;
					padding-left:10px;
					padding-right:10px;
					padding-top:10px;
					padding-bottom:2px;
					font-weight:normal;
				</xsl:attribute>
				<xsl:value-of select="$property"/>
			</td>
			<td>
				<xsl:attribute name="style">
					padding-top:10px;
					padding-right: 10px;
				</xsl:attribute>
				<ul>
				<xsl:for-each select="$list">
					<li>
						<xsl:choose>
							<xsl:when test="$displayname = '0'">
								<xsl:value-of select="."/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="ResourceManagementAttribute[AttributeName='DisplayName']/Value"/>
							</xsl:otherwise>
						</xsl:choose> 
					</li>
				</xsl:for-each>
				</ul>
			</td>
		</tr>
	</xsl:template>
  <!--======================================================================================-->
  <!-- Template to add a table style                                                        -->
  <!--======================================================================================-->
  <xsl:template name="tablestyle">
    <xsl:attribute name="style">
      font-family:Tahoma;
      font-size:11px;
      border-top:1px RGB(212,208,200) solid;
      border-left:1px RGB(212,208,200) solid;
      border-right: 1px RGB(212,208,200) solid;
      border-bottom:1px RGB(212,208,200) solid;
      padding:0px;
      border-collapse:collapse;
    </xsl:attribute>
  </xsl:template>
	<!--======================================================================================-->
	<!-- Template to add ainner table style                                                   -->
	<!--======================================================================================-->
	<xsl:template name="innertable">
		<xsl:attribute name="style">
			font-family:Tahoma;
			font-size:11px;
			border-collapse:collapse;
		</xsl:attribute>
	</xsl:template>
	<!--======================================================================================-->
  <!-- Template to add a report head style                                                  -->
  <!--======================================================================================-->
  <xsl:template name="reportheadstyle">
    <xsl:attribute name="style">
      padding-top:10px;
      padding-bottom:10px;
      padding-left:10px;
      padding-right:10px;
      font-weight:bold;
      background:rgb(234,242,255);
      border-bottom:1px solid rgb(120,172,255)
    </xsl:attribute>
  </xsl:template>
  <!--======================================================================================-->
  <!-- Template to add a section style                                                        -->
  <!--======================================================================================-->
  <xsl:template name="sectionstyle">
    <xsl:attribute name="style">
      text-align:left;
      border-bottom:green 1px solid;
      padding-bottom:5px;
      padding-left:10px;
      padding-right:10px;
      background:#e9ffcb;
      font-weight:bold;
      padding-top:5px
    </xsl:attribute>
  </xsl:template>
  <!--======================================================================================-->
  <!-- Template to add a section break                                                      -->
  <!--======================================================================================-->
  <xsl:template name="sectionbreak">
    <xsl:param name="colspan" />
    <xsl:if test="position()!=1">
      <tr>
        <td style="color:#FFFFFF;background-color:#FFFFFF; border-top:1px RGB(212,208,200) solid;" >
          <xsl:attribute name="colspan">
            <xsl:value-of select="$colspan"/>
          </xsl:attribute>
          &#160;
        </td>
      </tr>
    </xsl:if>
  </xsl:template>
	<!--======================================================================================-->
	<!-- Template to add a head style                                                        -->
	<!--======================================================================================-->
	<xsl:template name="headstyle">
		<xsl:attribute name="style">
			font-family:Tahoma;
			font-size:11px;
			background:#CCCCCC;
			border-right:#666666 1px solid;
			border-bottom:#666666 1px solid;
			padding-left:10px;
			padding-right:10px;
			font-weight:normal;
			white-space:nowrap;
		</xsl:attribute>
	</xsl:template>
	<!--===================================================================================================================================-->
	<!-- Script to convert XML Text into XML Node List                                                                                     -->
	<!--===================================================================================================================================-->
	<msxml:script language="CSharp" implements-prefix="mv">
		<msxml:using namespace="System.IO" />
		public XPathNodeIterator parse(string data)
		{
		String xmlString = "&lt;root&gt;" + data + "&lt;/root&gt;";
		StringReader stringReader = new StringReader(xmlString);

		XPathDocument xPathDocument = new XPathDocument(stringReader);
		XPathNavigator xPathNavigator = xPathDocument.CreateNavigator();

		return xPathNavigator.Select("root");
		}
	</msxml:script>
</xsl:stylesheet>